#include "LaSalle.h"
#include <math.h>
#include<string>
#include <iostream>
#include <fstream>

#define XXX 0;
using namespace std;

namespace Pulse
{	
	MenuButton::MenuButton( const HINSTANCE hInst, const char *pStateIdle, const char *pStateOver )
	: m_xPos( 0.0f ), m_yPos( 0.0f ), m_pStateIdle( NULL ), m_pStateOver( NULL ), m_state( IDLE )
	{
		if ( pStateIdle  )
			m_pStateIdle = new Bitmap( hInst, pStateIdle );
		
		if ( pStateOver )
			m_pStateOver = new Bitmap( hInst, pStateOver );			
	}

	MenuButton::~MenuButton( void )
	{
		if ( m_pStateIdle )
			delete m_pStateIdle;

		if ( m_pStateOver )
			delete m_pStateOver;
	}

	void MenuButton::Update( float mouseX, float mouseY )
	{
		POINT pnt = { (LONG)mouseX, (LONG)mouseY };
		RECT rect = { (LONG)(m_xPos), (LONG)(m_yPos), (LONG)(m_xPos + m_pStateIdle->GetWidth()),(LONG)( m_yPos + m_pStateIdle->GetHeight()) };

		if ( PointRectCollisionCheck( pnt, rect ) )
			m_state = OVER;
		else
			m_state = IDLE;
	}

	BOOL MenuButton::IsMenuButtonClicked( void )
	{	
		return gpWinApp->IsBufferedKeyDown( VK_LBUTTON ) && m_state == OVER;
	}

	void MenuButton::Render( HDC bbDC, HDC spriteDC )
	{
		switch( m_state )
		{
		case IDLE:
			m_pStateIdle->Render( bbDC, spriteDC, (INT)m_xPos, (INT)m_yPos );
			break;
		case OVER:
			m_pStateOver->Render( bbDC, spriteDC, (INT)m_xPos, (INT)m_yPos );
			break;
		}
	}

	LaSalle::LaSalle( const HINSTANCE hInst, const CHAR *pStr, const INT posX, const INT posY, const INT width, const INT height )
		: WinApp( hInst, pStr, posX, posY, width, height )
	{

	}
	
	LaSalle::~LaSalle( void )
	{

	}

	BOOL LaSalle::OnStart( void )
	{
			WORDS = new String[50][2];
			WORDS[0][0] = "bi nary"; //Answ
			WORDS[0][1] = "bi nary"; //Ques
			WORDS[1][0] = "ba ckup";  //Ans
			WORDS[1][1] = "ba ckup"; //Qstn
			WORDS[2][0] = "ba itware";
			WORDS[2][1] = "ba itware";
			WORDS[3][0] = "be tbug";
			WORDS[3][1] = "be tbug";
			WORDS[4][0] = "fr eeware";
			WORDS[4][1] = "fr eeware";
			WORDS[5][0] = "ar ray";
			WORDS[5][1] = "ar ray";
			WORDS[6][0] = "by te";
			WORDS[6][1] = "by te";
			WORDS[7][0] = "bo ot";
			WORDS[7][1] = "bo ot";
			WORDS[8][0] = "mi rroring";
			WORDS[8][1] = "mi rroring";
			WORDS[9][0] = "programmer";
			WORDS[9][1] = "pr ogrammer";
			WORDS[10][1] = "na vigate";
			WORDS[10][0] = "na vigate";
			WORDS[11][0] = "sc roll";
			WORDS[11][1] = "sc roll";
			WORDS[12][0] = "so ftware";
			WORDS[12][1] = "so ftware";
			WORDS[13][0] = "sp eakers";
			WORDS[13][1] = "sp eakers";
			WORDS[14][0] = "we bsite";
			WORDS[14][1] = "we bsite";
			WORDS[15][0] = "wi ndow";
			WORDS[15][1] = "wi ndow";
			WORDS[16][0] = "al gorithm";
			WORDS[16][1] = "al gorithm";
			WORDS[17][0] = "ap plet";
			WORDS[17][1] = "ap plet";
			WORDS[18][0] = "ap plicatio";
			WORDS[18][1] = "ap plicatio";
			WORDS[19][0] = "ar chive";
			WORDS[19][1] = "ar chive";
			WORDS[20][0] = "as cii";
			WORDS[20][1] = "as cii";

		TotalQuestionsFromFile = 0;
		Credih = 0;
		BckTomain = true;
		mLastPosX = 0;
		for(int x =0; x<12;x++)
		{
			HSCORE[x] = 0;
		}
		RanOne = 0;

		stopOutFile = false;
		MyHighScore = 0;
		getInputFile = true;
		getOutPutFile = false;
		m_PlayState = MENU;  
		//m_PlayState = LogIn;
		//m_PlayState = HighScore;
		mGameCategory = LaSalle::NONE;
		// OnStart() funtion isCalled just before the app enters in the main loop.
       
		//--------------------------------------------------------------------------
        //Main Menu
        //-------------------------------------------------------------------------
       	m_pPlayMenuButton = new MenuButton(GetHInstance(), "Resources/MainMenu/MainMenu_PlayButton.bmp","Resources/MainMenu/MainMenu_PlayButton.bmp");
		m_pPlayMenuButton->SetPos(322,199); //upperleft part pos of the button

		m_pCreditsMenuButton = new MenuButton(GetHInstance(), "Resources/MainMenu/MainMenu_CreditsButton.bmp","Resources/MainMenu/MainMenu_CreditsButton.bmp");
		m_pCreditsMenuButton->SetPos(59,514);

		m_pHelpMenuButton = new MenuButton(GetHInstance(), "Resources/MainMenu/MainMenu_HelpButton.bmp","Resources/MainMenu/MainMenu_HelpButton.bmp");
		m_pHelpMenuButton->SetPos(598,412);

		m_pExitMenuButton = new MenuButton(GetHInstance(), "Resources/MainMenu/MainMenu_ExitButton.bmp","Resources/MainMenu/MainMenu_ExitButton.bmp");
		m_pExitMenuButton->SetPos(431,499);
           
		m_pMainMenuBackground = new Bitmap (GetHInstance(), "Resources/MainMenu/MainMenuBackGround.bmp");
		m_pCreditsBackground = new BitmapMasked (GetHInstance(), "Resources/MainMenu/CreditsBackGround.bmp",RGB(0,0,0));
		m_pHelpBackground = new Bitmap (GetHInstance(), "Resources/MainMenu/HelpBackGround.bmp");
		m_pReviewBackground = new Bitmap (GetHInstance(), "Resources/MainMenu/ReviewBackGround.bmp");
		m_pReviewBackground2 = new Bitmap (GetHInstance(), "Resources/MainMenu/ReviewBackGround2.bmp");
		m_pReviewBackground3 = new Bitmap (GetHInstance(), "Resources/MainMenu/ReviewBackGround3.bmp");

		EatLetters.LoadSound("Resources/Sounds/eat.wav");
		ButtonClick.LoadSound("Resources/Sounds/button_click.wav");
		MainMenuSound.LoadSound("Resources/Sounds/MainMenuBg.mp3");
		MainMenuSound.SetLoop(true);
		waterloop1.LoadMusic("Resources/Sounds/waterloop1.wav");
		waterloop1.SetLoop(TRUE);
		MainMenuSound.Play();
		
		//--------------------------------------------------
		//LogIn Screen
		//--------------------------------------------------
		mPlayer.SetName("Name");
		m_pLogInBackGround = new Bitmap(GetHInstance(),"Resources/LogIn/LogInBg.bmp"); 
		//----------------------------------------------------------------------------
		//PlayScreen
		//----------------------------------------------------------------------------
		m_pMovingGreenFish = new Animation;
		m_pMovingGreenFish->AddFrame(new BitmapMasked( GetHInstance(), "Resources/Play/GreenFish_1.bmp", RGB( 34, 177, 76 )  ));
        m_pMovingGreenFish->AddFrame(new BitmapMasked( GetHInstance(), "Resources/Play/GreenFish_2.bmp", RGB( 34, 177, 76 )  ));
        m_pMovingGreenFish->AddFrame(new BitmapMasked( GetHInstance(), "Resources/Play/GreenFish_3.bmp", RGB( 34, 177, 76 )  ));
        m_pMovingGreenFish->SetSPF(1.0f/10.0f); //seconds per frame to animate;
		
		m_pMovingGreenFish2 = new Animation;
		m_pMovingGreenFish2->AddFrame(new BitmapMasked( GetHInstance(), "Resources/Play/GreenFishSideB_1.bmp", RGB( 34, 177, 76 )  ));
        m_pMovingGreenFish2->AddFrame(new BitmapMasked( GetHInstance(), "Resources/Play/GreenFishSideB_2.bmp", RGB( 34, 177, 76 )  ));
        m_pMovingGreenFish2->AddFrame(new BitmapMasked( GetHInstance(), "Resources/Play/GreenFishSideB_3.bmp", RGB( 34, 177, 76 )  ));
        m_pMovingGreenFish2->SetSPF(1.0f/10.0f); //seconds per frame to animate;

		m_pBackGround = new Bitmap(GetHInstance(),"Resources/Play/PlayBackGround.bmp");
		
		mpFishLives = new BitmapMasked(GetHInstance(),"Resources/Play/Life.bmp");

		m_FishPosX = 0.0f;
		m_FishPosY = 0.0f;
		mScore = 0.0f;
		mGameTimer = 0.0f;
		mLives = 0;
		mCorrectAnswers = 0;

		mPlayerAnswer[0] = '*';
		Alphabet = "abcdefghijklmnopqrstuvwxyz ";
		mNumOfQuestions = 0;
		//mTimer.SetStartTime(120.0f);
				
		m_pFood = new Bitmap(GetHInstance(),"Resources/Tiles/a.bmp");	
		
		//Special char art
		//SpecialChar[0] = new BitmapMasked ( GetHInstance(), "Resources/Tiles/a.bmp",RGB(255,255,255));

		//LETTERS ART
		letters[0]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/a.bmp",RGB(255,255,255));
		letters[1]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/b.bmp",RGB(255,255,255));
		letters[2]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/c.bmp",RGB(255,255,255));
		letters[3]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/d.bmp",RGB(255,255,255));
		letters[4]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/e.bmp",RGB(255,255,255));
		letters[5]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/f.bmp",RGB(255,255,255));
		letters[6]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/g.bmp",RGB(255,255,255));
		letters[7]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/h.bmp",RGB(255,255,255));
		letters[8]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/i.bmp",RGB(255,255,255));
		letters[9]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/j.bmp",RGB(255,255,255));
		letters[10]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/k.bmp",RGB(255,255,255));
		letters[11]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/l.bmp",RGB(255,255,255));
		letters[12]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/m.bmp",RGB(255,255,255));
		letters[13]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/n.bmp",RGB(255,255,255));
		letters[14]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/o.bmp",RGB(255,255,255));
		letters[15]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/p.bmp",RGB(255,255,255));
		letters[16]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/q.bmp",RGB(255,255,255));
		letters[17]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/r.bmp",RGB(255,255,255));
		letters[18]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/s.bmp",RGB(255,255,255));
		letters[19]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/t.bmp",RGB(255,255,255));
		letters[20]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/u.bmp",RGB(255,255,255));
		letters[21]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/v.bmp",RGB(255,255,255));
		letters[22]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/w.bmp",RGB(255,255,255));
		letters[23]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/x.bmp",RGB(255,255,255));
		letters[24]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/y.bmp",RGB(255,255,255));
		letters[25]= new BitmapMasked ( GetHInstance(), "Resources/Tiles/z.bmp",RGB(255,255,255));
		letters[26] = new BitmapMasked ( GetHInstance(), "Resources/Tiles/space.bmp",RGB(255,255,255));																	  
		mFishFood.Load(letters[0]);											  
		mFishFood.SetStartPos(114, -97);									  
		mFishFoodB.Load(letters[1]);										  
		mFishFoodB.SetStartPos(175, -97);
		mFishFoodC.Load(letters[2]);
		mFishFoodC.SetStartPos(243, -97);
		mFishFoodD.Load(letters[3]);
		mFishFoodD.SetStartPos(311, -97);
		mFishFoodE.Load(letters[4]);
		mFishFoodE.SetStartPos(379, -97);
		mFishFoodF.Load(letters[5]);
		mFishFoodF.SetStartPos(447, -97);
		mFishFoodG.Load(letters[6]);
		mFishFoodG.SetStartPos(515, -97);
		mFishFoodH.Load(letters[7]);
		mFishFoodH.SetStartPos(585, -97);
		mFishFoodI.Load(letters[8]);
		mFishFoodI.SetStartPos(653, -97);
		mFishFoodJ.Load(letters[9]);
		mFishFoodJ.SetStartPos(721, -97);
		mFishFoodK.Load(letters[10]);
		mFishFoodK.SetStartPos(789, -97);
		mFishFoodL.Load(letters[11]);
		mFishFoodL.SetStartPos(857, -97);
		mFishFoodM.Load(letters[12]);
		mFishFoodM.SetStartPos(114, -177);
		mFishFoodN.Load(letters[13]);
		mFishFoodN.SetStartPos(175, -177);
		mFishFoodO.Load(letters[14]);
		mFishFoodO.SetStartPos(243, -177);
		mFishFoodP.Load(letters[15]);
		mFishFoodP.SetStartPos(311, -177);
		mFishFoodQ.Load(letters[16]);
		mFishFoodQ.SetStartPos(379, -177);
		mFishFoodR.Load(letters[17]);
		mFishFoodR.SetStartPos(447, -177);
		mFishFoodS.Load(letters[18]);
		mFishFoodS.SetStartPos(515, -177);
		mFishFoodT.Load(letters[19]);
		mFishFoodT.SetStartPos(585, -177);
		mFishFoodU.Load(letters[20]);
		mFishFoodU.SetStartPos(653, -177);
		mFishFoodV.Load(letters[21]);
		mFishFoodV.SetStartPos(721, -177);
		mFishFoodW.Load(letters[22]);
		mFishFoodW.SetStartPos(789, -177);
		mFishFoodX.Load(letters[23]);
		mFishFoodX.SetStartPos(857, -177);
		mFishFoodY.Load(letters[24]);
		mFishFoodY.SetStartPos(114, -287);
		mFishFoodZ.Load(letters[25]);
		mFishFoodZ.SetStartPos(175, -287);
		mSpace.Load(letters[26]);
		mSpace.SetStartPos(175+61, -287);
		
		for(int x = 0; x<27; x++)
		{
			isVisible[x] = false ;
		}

		WORDS = new String [21][2];
		mResetQuestion = true;

		//----------------------------
		//PopUps
		//----------------------------
		m_pGameOverPopUp = new Bitmap(GetHInstance(),"Resources/PopUp/GameOver.bmp");
		m_pWrongAnswer = new Bitmap(GetHInstance(),"Resources/PopUp/WrongAnswer.bmp");
		m_pCorrectAnswer = new Bitmap(GetHInstance(),"Resources/PopUp/CorrectAnswer.bmp");

		m_pLevelOneComplete = new Bitmap(GetHInstance(),"Resources/PopUp/LevelOneComplete.bmp");
		m_pLevelTwoComplete = new Bitmap(GetHInstance(),"Resources/PopUp/LevelTwoComplete.bmp");
		m_pLevelThreeComplete = new Bitmap(GetHInstance(),"Resources/PopUp/LevelThreeComplete.bmp");

		ShowPopUpCorrectAnswer =false;
		ShowPopUpWrongAnswer = false;
		ShowPopUplevel1Complete = false;
		ShowPopUplevel2Complete = false;
		ShowPopUplevel3Complete = false;

		//------------
		//HighScore
		//------------
		m_pHighScoreBg = new Bitmap(GetHInstance(),"Resources/PopUp/HighScorePage.bmp"); 

		ifstream getnamefile2( "Vc90.dat" );
		if( getnamefile2.is_open() )
		{		
			getnamefile2.getline(mEngine,90,'\n');
			getnamefile2.getline(mEngine2,90,'x');
			getnamefile2.close();			
		}

		ifstream getNumOfQuestionsFile( "NumOfQuestions.txt" );
		if( getNumOfQuestionsFile.is_open() )
		{
			getNumOfQuestionsFile>>totalEasyQuestions;
			getNumOfQuestionsFile>>totalMediumQuestions;
			getNumOfQuestionsFile>>totalHardQuestions;
			getNumOfQuestionsFile.close();
		}	

		popuptimer = 0;	
		
		return TRUE;
	}
	
	BOOL LaSalle::OnUpdate( FLOAT dt )
	{
		BOOL bReturn = true;
       		
		if (Credih > 505.0f)
		{
			m_pCredihMenuButton->Update(0,0);
		}
        switch( m_PlayState )
		{
		case MENU:
			bReturn = OnMenuUpdate( dt );
			break;
		case LogIn:
			OnLogInUpdate( dt );
			break;
		case Play:
			OnPlayUpdate( dt );
			break;
		case Credits:
			if(IsBufferedKeyDown( VK_ESCAPE ))
			{
				//Back to Main Menu
				HandleStateChange(MENU);
			}
			OnCreditsUpdate( dt );
			break;
		case Help:
			if(IsBufferedKeyDown( VK_ESCAPE ))
			{
				//Back to Main Menu
				HandleStateChange(MENU);
			}
			OnHelpUpdate( dt );
			break;
		case HighScore:
			OnHighScoreUpdate( dt );
			break;
		case Story:
			OnStoryUpdate( dt );
			break;
		case Exit:
			OnExitUpdate( dt );
			break;
		}
        return bReturn;	
    }
	
	BOOL LaSalle::OnRender( void )
	{
        switch( m_PlayState )
		{
		case MENU:
			OnMenuRender();
			break;
		case LogIn:
			OnLogInRender();
			break;
		case Play:
			OnPlayRender();
			break;
		case Credits:
			OnCreditsRender();
			break;
		case Help:
			OnHelpRender();
			break;
		case Story:
			OnStoryRender();
			break;
		case HighScore:
			OnHighScoreRender();
			break;
		case Exit:
			OnExitRender();
			break;			
		}	
		
		return TRUE;
	}
	
	BOOL LaSalle::OnExit( void )
	{
       //NOTE: Deleting a pointer and setting it no null..
       // not sure if its a good thing to do.. might hide errors. Research!.
       //  delete = delete the memory that the pointer is pointing to
        
        //MainMenu
        delete m_pMainMenuBackground;

        delete m_pPlayMenuButton;
        delete m_pCreditsMenuButton;
        delete m_pHelpMenuButton;
        delete m_pExitMenuButton;
		
		ButtonClick.Release();
		MainMenuSound.Release();
		EatLetters.Release();
		waterloop1.Release();
		
       // if( assert(m_pPlayMenuButtonm_ != 0))
        m_pPlayMenuButton = NULL;    

        return 0;
	}

	void LaSalle::HandleStateChange( Play_STATE state )
	{
		switch( state )
		{
		case MENU:
			
			stopOutFile = false;
			mGameCategory = LaSalle::NONE;
			MyHighScore = 0;
			MainMenuSound.Stop();
			MainMenuSound.Play();
			waterloop1.Stop();
			
			break;
			
			case Play:
			
			
			TotalQuestionsFromFile = 0;
			getInputFile = 1;
			BckTomain = true;
			mLastPosX = 0;
			popuptimer = 0;
			
			MainMenuSound.Pause();
			waterloop1.Play();
			mGameCategory = LaSalle::EASY;
			//Position xy of the Fish
			m_posX1 = 0.0f; 
			m_posY1 = 0.0f;
			
			//SCORE, TIME, LIVES
			mScore = 0;
			mGameTimer = 300.0f;
			mLives = 3;
			mCorrectAnswers = 0;
				
			accept = true;
			speedy = 0.0f;
			AnsIndex = 0;
									
			mResetQuestion = true;
			mQuestionToShow[0] =  '\0' ;
			Ex = "Answer";
			mScore = 0;
			mStartGame = true;

			for(int x = 0; x<27; x++)
			{
				isVisible[x] = 0 ;
			}
			ShowPopUpCorrectAnswer =false;
			ShowPopUpWrongAnswer = false;

			ShowPopUplevel1Complete = false;
			ShowPopUplevel2Complete = false;
			ShowPopUplevel3Complete = false;
			
			mPlayerAnswer[0] = '\0';
			// reset some data everytime you enter this stae
			
			break;
		case LogIn:
			mPlayer.SetName("Name");
			break;
		case Credits:
			Credih = 500.0f;
            break;
		case Help:
			Credih = 500.0f;
			break;
		case Story: //review
			Review = 0;
			break;
		case HighScore:
			getInputFile = 1;
			getOutPutFile = 0;
			waterloop1.Stop();
			break;
		case Exit:
			break;
		};
		m_PlayState = state;
	}

	BOOL LaSalle::OnMenuUpdate( FLOAT dt )
	{	
		POINT mousePos;
		GetAppCursorPos( mousePos );

		RECT Review;
		Review.left =375 ;
		Review.top =325;
		Review.right = Review.left + 323;
		Review.bottom = Review.top + 61;

		RECT high;
		high.left =255 ;
		high.top =415;
		high.right = high.left + 242;
		high.bottom = high.top + 62;

		if( PointRectCollisionCheck( mousePos, high ) && IsBufferedKeyDown(VK_LBUTTON))
		{
			HandleStateChange(HighScore);
		}

		if( PointRectCollisionCheck( mousePos, Review ) && IsBufferedKeyDown(VK_LBUTTON))
		{
			HandleStateChange(Story);
		}
	

        //Detect if Mouse is colliding with button
		m_pPlayMenuButton->Update( mousePos.x, mousePos.y );
		m_pCreditsMenuButton->Update( mousePos.x, mousePos.y );
		m_pHelpMenuButton->Update( mousePos.x, mousePos.y );
		m_pExitMenuButton->Update( mousePos.x, mousePos.y );

		if ( m_pPlayMenuButton->IsMenuButtonClicked() )
		{
			ButtonClick.Play();
			HandleStateChange( LogIn );
		}
		else if ( m_pCreditsMenuButton->IsMenuButtonClicked() )
		{
			ButtonClick.Play();
			HandleStateChange( Credits );
		}
		else if ( m_pHelpMenuButton->IsMenuButtonClicked() )
		{
			ButtonClick.Play();
			HandleStateChange( Help );
		}
		else if ( m_pExitMenuButton->IsMenuButtonClicked() )
		{
			return FALSE;
			//HandleStateChange( Exit );
		}
		return TRUE;
	}

	BOOL LaSalle::OnMenuRender( void )
	{
		m_pBackBuffer->Clear();
		HDC bbDC = m_pBackBuffer->GetDC();
				
		m_pMainMenuBackground->Render( bbDC, m_spriteDC, 0, 0 );

		m_pPlayMenuButton->Render( bbDC, m_spriteDC );
		m_pCreditsMenuButton->Render( bbDC, m_spriteDC );
		m_pHelpMenuButton->Render( bbDC, m_spriteDC );
		m_pExitMenuButton->Render( bbDC, m_spriteDC );
				
		m_pBackBuffer->Present();
		
		return TRUE;
	}

	BOOL LaSalle::OnPlayUpdate( FLOAT dt )
	{			
		if(IsBufferedKeyDown(VK_ESCAPE))
		{
			HandleStateChange(MENU);
		}
		
		//TEST CODE
		//Increment numCorrectAnswers
		if(IsBufferedKeyDown('Q'))
		{
			mCorrectAnswers++;
			mScore+= 20;
			ShowPopUpCorrectAnswer = true;
		}
		
		//Update Category/correct answers
		if(mCorrectAnswers == 5 && mGameCategory == LaSalle::EASY)
		{
				ShowPopUplevel1Complete = true;
			
				mCorrectAnswers = 0;
				mGameTimer = 300.0f;
				mGameCategory =  LaSalle::MEDIUM;
				getInputFile = true;
				//ShowPopUplevel1Complete = false;
			
			
		}
		else if(mCorrectAnswers == 5 && mGameCategory == LaSalle::MEDIUM)
		{		
						
			ShowPopUplevel2Complete = true;
			
				//ShowPopUplevel2Complete = false;
				
				mGameCategory =  LaSalle::HARD;
				mCorrectAnswers = 0;
				mGameTimer = 300.0f;
				getInputFile = true;
		}
		else if(mCorrectAnswers == 5 && mGameCategory == LaSalle::HARD)
		{
			//RENDER YOU WIN MESSAGE
			ShowPopUplevel3Complete = true;
			//STATE CHANGE TO HIGH SCORE
		}
		//CATEGORY
		if(mGameCategory == LaSalle::EASY)
		{
			TotalQuestionsFromFile = totalEasyQuestions;
			///------
		if(getInputFile)
		{
			//WORDS = new String [21][2];
		//HERE	
			int x = 0;
			ifstream getnamefile2( "EasyQuestions.txt" );
			if( getnamefile2.is_open() )
			{		
				do
				{
					char ipot[256] = "";
					char ipot2[256] = "";
					getnamefile2.getline(ipot,256,'\n');//.getline(ipot,10,'/n');
					
					getnamefile2.getline(ipot2,256,'\n');//.getline(ipot,10,'/n');
					//getnamefile2.getline(ipot2,10,'/n');
						WORDS[x][0] = ipot;
						WORDS[x][1] = ipot2;
						x++;				
					
				} while(/*WORDS[x-1][0]!= "END" ||WORDS[x-1][1] != "END"*/x<totalEasyQuestions);

				
				getnamefile2.close();
			getInputFile = false;						
		}
		}

			//------
			//WORDS[0][0] = "bi nary"; //Answer
			//WORDS[0][1] = "bi nary"; //Question
			//WORDS[1][0] = "ba ckup";  //Anser
			//WORDS[1][1] = "ba ckup"; //Qstn...
			//WORDS[2][0] = "ba itware";
			//WORDS[2][1] = "ba itware";
			//WORDS[3][0] = "be tbug";
			//WORDS[3][1] = "be tbug";
			//WORDS[4][0] = "fr eeware";
			//WORDS[4][1] = "fr eeware";
			//WORDS[5][0] = "ar ray";
			//WORDS[5][1] = "ar ray";
			//WORDS[6][0] = "by te";
			//WORDS[6][1] = "by te";
			//WORDS[7][0] = "bo ot";
			//WORDS[7][1] = "bo ot";
			//WORDS[8][0] = "mi rroring";
			//WORDS[8][1] = "mi rroring";
			//WORDS[9][0] = "programmer";
			//WORDS[9][1] = "pr ogrammer";
			//WORDS[10][1] = "na vigate";
			//WORDS[10][0] = "na vigate";
			//WORDS[11][0] = "sc roll";
			//WORDS[11][1] = "sc roll";
			//WORDS[12][0] = "so ftware";
			//WORDS[12][1] = "so ftware";
			//WORDS[13][0] = "sp eakers";
			//WORDS[13][1] = "sp eakers";
			//WORDS[14][0] = "we bsite";
			//WORDS[14][1] = "we bsite";
			//WORDS[15][0] = "wi ndow";
			//WORDS[15][1] = "wi ndow";
			//WORDS[16][0] = "al gorithm";
			//WORDS[16][1] = "al gorithm";
			//WORDS[17][0] = "ap plet";
			//WORDS[17][1] = "ap plet";
			//WORDS[18][0] = "ap plicatio";
			//WORDS[18][1] = "ap plicatio";
			//WORDS[19][0] = "ar chive";
			//WORDS[19][1] = "ar chive";
			//WORDS[20][0] = "as cii";
			//WORDS[20][1] = "as cii";
		}

		else if(mGameCategory == LaSalle::MEDIUM)
		{
			TotalQuestionsFromFile = totalMediumQuestions;
			if(getInputFile)
		{
			//WORDS = new String [21][2];
		//HERE	
			int x = 0;
			ifstream getnamefile2( "MediumQuestions.txt" );
			if( getnamefile2.is_open() )
			{		
				do
				{
					char ipot[256] = "";
					char ipot2[256] = "";
					getnamefile2.getline(ipot,256,'\n');//.getline(ipot,10,'/n');
					
					getnamefile2.getline(ipot2,256,'\n');//.getline(ipot,10,'/n');
					//getnamefile2.getline(ipot2,10,'/n');
						WORDS[x][0] = ipot;
						WORDS[x][1] = ipot2;
						x++;				
					
				} while(/*WORDS[x-1][0]!= "END" ||WORDS[x-1][1] != "END"*/x<totalMediumQuestions);

				
				getnamefile2.close();
			getInputFile = false;						
		}
		}
		}
		else if(mGameCategory == LaSalle::HARD)
		{
			TotalQuestionsFromFile = totalHardQuestions;
			if(getInputFile)
		{
			//WORDS = new String [21][2];
		//HERE	
			int x = 0;
			ifstream getnamefile2( "HardQuestions.txt" );
			if( getnamefile2.is_open() )
			{		
				do
				{
					char ipot[256] = "";
					char ipot2[256] = "";
					getnamefile2.getline(ipot,256,'\n');//.getline(ipot,10,'/n');
					
					getnamefile2.getline(ipot2,256,'\n');//.getline(ipot,10,'/n');
					//getnamefile2.getline(ipot2,10,'/n');
						WORDS[x][0] = ipot;
						WORDS[x][1] = ipot2;
						x++;				
					
				} while(/*WORDS[x-1][0]!= "END" ||WORDS[x-1][1] != "END"*/x<totalHardQuestions);

				
				getnamefile2.close();
			getInputFile = false;						
		}
		}
		}
		
		//MOuse pointer
		POINT mousePos;
		GetAppCursorPos( mousePos );
		
	
		//Start Game, start timer
		if(mStartGame)
		{
			mGameTimer-=dt;
			if(mGameTimer <= 0)
			{
				//mStartGame = false;
				mLives = 0;
			}
		
		//-------------------  
		//FISH MOVEMENT   
		//-------------------
		
		//speed of the green fish
		 const float speed = 200.0f; 

		if ( IsKeyDown( 'W') )
		{
			m_posY1 -= speed * dt;
			if (m_posY1 < 0)
				m_posY1 = 0;
		}
		else if ( IsKeyDown( 'A' ) )
		{
			m_posX1 -= speed * dt;
			if(m_posX1 < 0)
				m_posX1 = 0;
		}
		else if ( IsKeyDown( 'S' ) )
		{
			m_posY1 += speed * dt;
			//if(m_posY1 + m_pAnimFront->GetFrame(0)->GetWidth() > 1475)
		}
		else if ( IsKeyDown( 'D' ) )
		{
			m_posX1 += speed * dt;
		}

		if(mResetQuestion || IsBufferedKeyDown('V'))
		{
			srand(time(0));
			int choice = (rand() % TotalQuestionsFromFile);//20 befor
			mWordToGuess = WORDS[choice][0];
			//mWordToGuess = WORDS[0][0];
			//TODO:REVERT
			mQuestion = WORDS[choice][1];
			//mQuestion = WORDS[0][1]; //for test

			mJumbledWord = mWordToGuess;

			RanOne = (rand() % 16);
		
			for(int x = 0; x<27; x++)
			{
				isVisible[x] = 0 ;
			}
			
		mFishFood.SetStartPos(114, -97);									  
		mFishFoodB.SetStartPos(175, -97);
		mFishFoodC.SetStartPos(243, -97);
		mFishFoodD.SetStartPos(311, -97);
		mFishFoodE.SetStartPos(379, -97);
		mFishFoodF.SetStartPos(447, -97);
		mFishFoodG.SetStartPos(515, -97);
		mFishFoodH.SetStartPos(585, -97);
		mFishFoodI.SetStartPos(653, -97);
		mFishFoodJ.SetStartPos(721, -97);
		mFishFoodK.SetStartPos(789, -97);
		mFishFoodL.SetStartPos(857, -97);
		mFishFoodM.SetStartPos(114, -177);
		mFishFoodN.SetStartPos(175, -177);
		mFishFoodO.SetStartPos(243, -177);
		mFishFoodP.SetStartPos(311, -177);
		mFishFoodQ.SetStartPos(379, -177);
		mFishFoodR.SetStartPos(447, -177);
		mFishFoodS.SetStartPos(515, -177);
		mFishFoodT.SetStartPos(585, -177);
		mFishFoodU.SetStartPos(653, -177);
		mFishFoodV.SetStartPos(721, -177);
		mFishFoodW.SetStartPos(789, -177);
		mFishFoodX.SetStartPos(857, -177);
		mFishFoodY.SetStartPos(114, -287);
		mFishFoodZ.SetStartPos(175, -287);
		mSpace.SetStartPos(175+61, -287);
		mResetQuestion = false;

		}

		for(int a = 0; a <mQuestion.GetLength(); a++)
		{
			mQuestionToShow[a] = mQuestion[a];
			mQuestionToShow[a+1] = '\0';
		}

		m_pMovingGreenFish->Play();
		m_pMovingGreenFish->Update(dt);

		m_pMovingGreenFish2->Play();
		m_pMovingGreenFish2->Update(dt);

		RECT RectMovingGreenFish = {(LONG)(mousePos.x - 49), (LONG)(mousePos.y-40), RectMovingGreenFish.left + 98,RectMovingGreenFish.top+ 81};
				
		for(int x = 0; x<mJumbledWord.GetLength(); x++)
		{
			for(int y = 0; y<27; y++)
			{
			//If Jumbled word contains the letter
				if(mJumbledWord[x] == Alphabet[y])
				{
					if(isVisible[y] == 1)
					{
						isVisible[y] = 2;
					}
					else
					{
						isVisible[y] = 1;
					}
				}
			}
		}
		if(mGameCategory == GameCategory::MEDIUM)
		{
			if(isVisible[RanOne] == 0)
			{
				isVisible[RanOne] = 1;
			}
			else if(isVisible[RanOne] == 1)
			{
					isVisible[RanOne] = 2;
			}
			
			if(isVisible[RanOne+4] == 0)
			{
				isVisible[RanOne+4] = 1;
			}
			else if(isVisible[RanOne+4] == 1)
			{
					isVisible[RanOne+4] = 2;
			}
			
			if(isVisible[RanOne+8] == 0)
			{
				isVisible[RanOne+8] = 1;
			}
			else if(isVisible[RanOne+8] == 1)
			{
					isVisible[RanOne+8] = 2;
			}					
		}

		if(mGameCategory == GameCategory::HARD)
		{					
			if(isVisible[RanOne+1] == 0)
			{
				isVisible[RanOne+1] = 1;
			}
			else if(isVisible[RanOne+1] == 1)
			{
				isVisible[RanOne+1] = 2;
			}
			
			if(isVisible[25] == 0)
			{
				isVisible[25] = 1;
			}
			else if(isVisible[25] == 1)
			{
				isVisible[25] = 2;
			}

			if(isVisible[4] == 0)
			{
				isVisible[4] = 1;
			}
			else if(isVisible[4] == 1)
			{
				isVisible[4] = 2;
			}

			if(isVisible[22] == 0)
			{
				isVisible[22] = 1;
			}
			else if(isVisible[22] == 1)
			{
				isVisible[22] = 2;
			}
			
			//PUUYIH: HA
			if(isVisible[RanOne+7] == 0)
			{
				isVisible[RanOne+7] = 1;
			}
			else if(isVisible[RanOne+7] == 1)
			{
				isVisible[RanOne+7] = 2;
			}
			
			if(isVisible[RanOne+9] == 0)
			{
				isVisible[RanOne+9] = 1;
			}
			else if(isVisible[RanOne+9] == 1)
			{
					isVisible[RanOne+9] = 2;
			}				
		}
		mFishFood.Update(RectMovingGreenFish, dt ,isVisible[0]);
		mFishFoodB.Update(RectMovingGreenFish, dt,isVisible[1]);
		mFishFoodC.Update(RectMovingGreenFish, dt,isVisible[2]);
		mFishFoodD.Update(RectMovingGreenFish, dt,isVisible[3]);
		mFishFoodE.Update(RectMovingGreenFish, dt,isVisible[4]);
		mFishFoodF.Update(RectMovingGreenFish, dt,isVisible[5]);
		mFishFoodG.Update(RectMovingGreenFish, dt,isVisible[6]);
		mFishFoodH.Update(RectMovingGreenFish, dt,isVisible[7]);
		mFishFoodI.Update(RectMovingGreenFish, dt,isVisible[8]);
		mFishFoodJ.Update(RectMovingGreenFish, dt,isVisible[9]);
		mFishFoodK.Update(RectMovingGreenFish, dt,isVisible[10]);
		mFishFoodL.Update(RectMovingGreenFish, dt,isVisible[11]);
		mFishFoodM.Update(RectMovingGreenFish, dt,isVisible[12]);
		mFishFoodN.Update(RectMovingGreenFish, dt,isVisible[13]);
		mFishFoodO.Update(RectMovingGreenFish, dt,isVisible[14]);
		mFishFoodP.Update(RectMovingGreenFish, dt,isVisible[15]);
		mFishFoodQ.Update(RectMovingGreenFish, dt,isVisible[16]);
		mFishFoodR.Update(RectMovingGreenFish, dt,isVisible[17]);
		mFishFoodS.Update(RectMovingGreenFish, dt,isVisible[18]);
		mFishFoodT.Update(RectMovingGreenFish, dt,isVisible[19]);
		mFishFoodU.Update(RectMovingGreenFish, dt,isVisible[20]);
		mFishFoodV.Update(RectMovingGreenFish, dt,isVisible[21]);
		mFishFoodW.Update(RectMovingGreenFish, dt,isVisible[22]);
		mFishFoodX.Update(RectMovingGreenFish, dt,isVisible[23]);
		mFishFoodY.Update(RectMovingGreenFish, dt,isVisible[24]);	
		mFishFoodZ.Update(RectMovingGreenFish, dt,isVisible[25]);
		mSpace.Update(RectMovingGreenFish, dt,isVisible[26]);

		//----------------------------------------
		//Getting the answer 
		//----------------------------------------
		RECT RectA;
		RectA.left = (LONG)(mFishFood.mPosX);
		RectA.top = (LONG)(mFishFood.mPosY);
		RectA.right = mFishFood. mPosX + m_pFood->GetWidth();
		RectA.bottom = mFishFood.mPosY + m_pFood->GetHeight();

		RECT RectB;
		RectB.left = (LONG)(mFishFoodB.mPosX);
		RectB.top = (LONG)(mFishFoodB.mPosY);
		RectB.right = mFishFoodB. mPosX + m_pFood->GetWidth();
		RectB.bottom = mFishFoodB.mPosY + m_pFood->GetHeight();

		RECT RectC;
		RectC.left = (LONG)(mFishFoodC.mPosX);
		RectC.top = (LONG)(mFishFoodC.mPosY);
		RectC.right = mFishFoodC. mPosX + m_pFood->GetWidth();
		RectC.bottom = mFishFoodC.mPosY + m_pFood->GetHeight();

		RECT RectD;
		RectD.left = (LONG)(mFishFoodD.mPosX);
		RectD.top = (LONG)(mFishFoodD.mPosY);
		RectD.right = mFishFoodD. mPosX + m_pFood->GetWidth();
		RectD.bottom = mFishFoodD.mPosY + m_pFood->GetHeight();

		RECT RectE;
		RectE.left = (LONG)(mFishFoodE.mPosX);
		RectE.top = (LONG)(mFishFoodE.mPosY);
		RectE.right = mFishFoodE. mPosX + m_pFood->GetWidth();
		RectE.bottom = mFishFoodE.mPosY + m_pFood->GetHeight();

		RECT RectF;
		RectF.left = (LONG)(mFishFoodF.mPosX);
		RectF.top = (LONG)(mFishFoodF.mPosY);
		RectF.right =mFishFoodF. mPosX + m_pFood->GetWidth();
		RectF.bottom = mFishFoodF.mPosY + m_pFood->GetHeight();

		RECT RectG;
		RectG.left = (LONG)(mFishFoodG.mPosX);
		RectG.top = (LONG)(mFishFoodG.mPosY);
		RectG.right = mFishFoodG. mPosX + m_pFood->GetWidth();
		RectG.bottom = mFishFoodG.mPosY + m_pFood->GetHeight();

		RECT RectH;
		RectH.left = (LONG)(mFishFoodH.mPosX);
		RectH.top = (LONG)(mFishFoodH.mPosY);
		RectH.right = mFishFoodH. mPosX + m_pFood->GetWidth();
		RectH.bottom = mFishFoodH.mPosY + m_pFood->GetHeight();

		RECT RectI;
		RectI.left = (LONG)(mFishFoodI.mPosX);
		RectI.top = (LONG)(mFishFoodI.mPosY);
		RectI.right = mFishFoodI. mPosX + m_pFood->GetWidth();
		RectI.bottom = mFishFoodI.mPosY + m_pFood->GetHeight();

		RECT RectJ;
		RectJ.left = (LONG)(mFishFoodJ.mPosX);
		RectJ.top = (LONG)(mFishFoodJ.mPosY);
		RectJ.right = mFishFoodJ. mPosX + m_pFood->GetWidth();
		RectJ.bottom = mFishFoodJ.mPosY + m_pFood->GetHeight();

		RECT RectK;
		RectK.left = (LONG)(mFishFoodK.mPosX);
		RectK.top = (LONG)(mFishFoodK.mPosY);
		RectK.right = mFishFoodK. mPosX + m_pFood->GetWidth();
		RectK.bottom = mFishFoodK.mPosY + m_pFood->GetHeight();

		RECT RectL;
		RectL.left = (LONG)(mFishFoodL.mPosX);
		RectL.top = (LONG)(mFishFoodL.mPosY);
		RectL.right = mFishFoodL. mPosX + m_pFood->GetWidth();
		RectL.bottom = mFishFoodL.mPosY + m_pFood->GetHeight();

		RECT RectM;
		RectM.left = (LONG)(mFishFoodM.mPosX);
		RectM.top = (LONG)(mFishFoodM.mPosY);
		RectM.right = mFishFoodM. mPosX + m_pFood->GetWidth();
		RectM.bottom = mFishFoodM.mPosY + m_pFood->GetHeight();

		RECT RectN;
		RectN.left = (LONG)(mFishFoodN.mPosX);
		RectN.top = (LONG)(mFishFoodN.mPosY);
		RectN.right = mFishFoodN. mPosX + m_pFood->GetWidth();
		RectN.bottom = mFishFoodN.mPosY + m_pFood->GetHeight();


		RECT RectO;
		RectO.left = (LONG)(mFishFoodO.mPosX);
		RectO.top = (LONG)(mFishFoodO.mPosY);
		RectO.right = mFishFoodO. mPosX + m_pFood->GetWidth();
		RectO.bottom = mFishFoodO.mPosY + m_pFood->GetHeight();

		RECT RectP;
		RectP.left = (LONG)(mFishFoodP.mPosX);
		RectP.top = (LONG)(mFishFoodP.mPosY);
		RectP.right = mFishFoodP. mPosX + m_pFood->GetWidth();
		RectP.bottom = mFishFoodP.mPosY + m_pFood->GetHeight();

		RECT RectQ;
		RectQ.left = (LONG)(mFishFoodQ.mPosX);
		RectQ.top = (LONG)(mFishFoodQ.mPosY);
		RectQ.right = mFishFoodQ. mPosX + m_pFood->GetWidth();
		RectQ.bottom = mFishFoodQ.mPosY + m_pFood->GetHeight();

		RECT RectR;
		RectR.left = (LONG)(mFishFoodR.mPosX);
		RectR.top = (LONG)(mFishFoodR.mPosY);
		RectR.right = mFishFoodR. mPosX + m_pFood->GetWidth();
		RectR.bottom = mFishFoodR.mPosY + m_pFood->GetHeight();

		RECT RectS;
		RectS.left = (LONG)(mFishFoodS.mPosX);
		RectS.top = (LONG)(mFishFoodS.mPosY);
		RectS.right = mFishFoodS. mPosX + m_pFood->GetWidth();
		RectS.bottom = mFishFoodS.mPosY + m_pFood->GetHeight();

		RECT RectT;
		RectT.left = (LONG)(mFishFoodT.mPosX);
		RectT.top = (LONG)(mFishFoodT.mPosY);
		RectT.right = mFishFoodT. mPosX + m_pFood->GetWidth();
		RectT.bottom = mFishFoodT.mPosY + m_pFood->GetHeight();

		RECT RectU;
		RectU.left = (LONG)(mFishFoodU.mPosX);
		RectU.top = (LONG)(mFishFoodU.mPosY);
		RectU.right = mFishFoodU. mPosX + m_pFood->GetWidth();
		RectU.bottom = mFishFoodU.mPosY + m_pFood->GetHeight();

		RECT RectV;
		RectV.left = (LONG)(mFishFoodV.mPosX);
		RectV.top = (LONG)(mFishFoodV.mPosY);
		RectV.right = mFishFoodV. mPosX + m_pFood->GetWidth();
		RectV.bottom = mFishFoodV.mPosY + m_pFood->GetHeight();

		RECT RectW;
		RectW.left = (LONG)(mFishFoodW.mPosX);
		RectW.top = (LONG)(mFishFoodW.mPosY);
		RectW.right = mFishFoodW. mPosX + m_pFood->GetWidth();
		RectW.bottom = mFishFoodW.mPosY + m_pFood->GetHeight();

		RECT RectX;
		RectX.left = (LONG)(mFishFoodX.mPosX);
		RectX.top = (LONG)(mFishFoodX.mPosY);
		RectX.right = mFishFoodX. mPosX + m_pFood->GetWidth();
		RectX.bottom = mFishFoodX.mPosY + m_pFood->GetHeight();

		RECT RectY;
		RectY.left = (LONG)(mFishFoodY.mPosX);
		RectY.top = (LONG)(mFishFoodY.mPosY);
		RectY.right =mFishFoodY. mPosX + m_pFood->GetWidth();
		RectY.bottom = mFishFoodY.mPosY + m_pFood->GetHeight();

		RECT RectZ;
		RectZ.left = (LONG)(mFishFoodZ.mPosX);
		RectZ.top = (LONG)(mFishFoodZ.mPosY);
		RectZ.right =mFishFoodZ. mPosX + m_pFood->GetWidth();
		RectZ.bottom = mFishFoodZ.mPosY + m_pFood->GetHeight();
		
		RECT RectSpace;
		RectSpace.left = (LONG)(mSpace.mPosX);
		RectSpace.top = (LONG)(mSpace.mPosY);
		RectSpace.right =mSpace. mPosX + m_pFood->GetWidth();
		RectSpace.bottom = mSpace.mPosY + m_pFood->GetHeight();

		//TODO: FIX
		if(mFishFood.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{	
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'a';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';		
			mFishFood.mVisibility = 2;
		}
		if(mFishFoodB.mVisibility == 1&&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ) )
		{
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'b';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodB.mVisibility = 2;
		}				
		if(mFishFoodC.mVisibility == 1&&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'c';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodC.mVisibility = 2;
		}			
		if(mFishFoodD.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{		
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'd';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodD.mVisibility = 2;

		}				
		if(mFishFoodE.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{		
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'e';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodE.mVisibility = 2;
		}				
		if(mFishFoodF.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{	
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'f';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodF.mVisibility = 2;
		}				
		if(mFishFoodG.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{			
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'g';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodG.mVisibility = 2;
		}				
		if(mFishFoodH.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{		
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'h';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodH.mVisibility = 2;
		}				
		if(mFishFoodI.mVisibility == 1&&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{		
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'i';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodI.mVisibility = 2;
		}				
		if(mFishFoodJ.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'j';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodJ.mVisibility = 2;
		}
		if(mFishFoodK.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{	
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'k';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodK.mVisibility = 2;
		}				
		if(mFishFoodL.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'l';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodL.mVisibility = 2;
		}				
		if(mFishFoodM.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{		
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'm';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodM.mVisibility = 2;
		}				
		if(mFishFoodN.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{		
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'n';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodN.mVisibility = 2;
		}				
		if(mFishFoodO.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'o';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodO.mVisibility = 2;
		}				
		if(mFishFoodP.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown(VK_LBUTTON ))
		{	
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'p';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodP.mVisibility = 2;
		}				
		if(mFishFoodQ.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON))
		{		
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'q';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodQ.mVisibility = 2;
		}			
		if(mFishFoodR.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{		
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'r';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodR.mVisibility = 2;
		}		
		if(mFishFoodS.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{	
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 's';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodS.mVisibility = 2;
		}		
		if(mFishFoodT.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{	
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 't';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodT.mVisibility = 2;
		}		
		if(mFishFoodU.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{	
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'u';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodU.mVisibility = 2;
		}		
		if(mFishFoodV.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{		
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'v';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodV.mVisibility = 2;
		}		
		if(mFishFoodW.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{	
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'w';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodW.mVisibility = 2;
		}		
		if(mFishFoodX.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'x';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodX.mVisibility = 2;
		}		
		if(mFishFoodY.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'y';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodY.mVisibility = 2;
		}		
		if(mFishFoodZ.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{	
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = 'z';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mFishFoodZ.mVisibility = 2;
		}		
		if(mSpace.mVisibility == 1 &&AnsIndex<=12 && IsBufferedKeyDown( VK_LBUTTON ))
		{	
			EatLetters.Play();
			mPlayerAnswer[AnsIndex] = ' ';
			AnsIndex++; 
			mPlayerAnswer[AnsIndex] = '\0';
			mSpace.mVisibility = 2;
		}	
		if(IsBufferedKeyDown(VK_RBUTTON)&& AnsIndex>0)
		{
			EatLetters.Play();

			AnsIndex--;
			if(AnsIndex>=1)
			{
				mPlayerAnswer[AnsIndex] = '\0';
			}
			else
			{
				mPlayerAnswer[AnsIndex] = '*';
			}
		}
		
		//EX is the string shown on screen, 

		Ex = mPlayerAnswer;

		if(IsBufferedKeyDown(VK_RETURN))
		{
			if (Ex == mWordToGuess)
			{
				mResetQuestion = true;
				mScore+= 20;
				mCorrectAnswers++;
				ShowPopUpCorrectAnswer = true;
				
				AnsIndex = 0;
				mStartGame = 0;
				mPlayerAnswer[0] = '\0';
				
				for(int x = 0; x<27; x++)
				{
					isVisible[x] = 0 ;
				}
			}
			else
			{
				mResetQuestion = true;
				mScore -= 30;
				AnsIndex = 0;
				mLives--;
				ShowPopUpWrongAnswer = true;
				mStartGame = 0;
				//TODO: Do something about the scoring system
				//Maybe lesser deduction and just proceed to the
				//next question... More like a pass.
			
				mPlayerAnswer[0] = '\0';
			}				
		}
	}//end of if mStartgame
		return TRUE;
	}

	BOOL LaSalle::OnPlayRender( void )
	{
		m_pBackBuffer->Clear();
		HDC bbDC = m_pBackBuffer->GetDC();				
	
		POINT mousePos;
		FPoint relPos;
		GetAppCursorPos( mousePos );

		//Background
		m_pBackGround->Render(bbDC, m_spriteDC, 0 ,0 );
		
		//LIVES
		if(mLives > 0)
		{
			mpFishLives->Render(bbDC,m_spriteDC,852,64);
		}
		if(mLives > 1)
		{
			mpFishLives->Render(bbDC,m_spriteDC,893,64);
		}
		if(mLives > 2)
		{
			mpFishLives->Render(bbDC,m_spriteDC,934,64);
		}		
	

		
		//The food
		mFishFood.Render(bbDC,  m_spriteDC,isVisible[0]);
		mFishFoodB.Render(bbDC, m_spriteDC,isVisible[1]);
		mFishFoodC.Render(bbDC, m_spriteDC,isVisible[2]);
		mFishFoodD.Render(bbDC, m_spriteDC,isVisible[3]);
		mFishFoodE.Render(bbDC, m_spriteDC,isVisible[4]);
		mFishFoodF.Render(bbDC, m_spriteDC,isVisible[5]);
		mFishFoodG.Render(bbDC, m_spriteDC,isVisible[6]);
		mFishFoodH.Render(bbDC, m_spriteDC,isVisible[7]);
		mFishFoodI.Render(bbDC, m_spriteDC,isVisible[8]);
		mFishFoodJ.Render(bbDC, m_spriteDC,isVisible[9]);
		mFishFoodK.Render(bbDC, m_spriteDC,isVisible[10]);
		mFishFoodL.Render(bbDC, m_spriteDC,isVisible[11]);
		mFishFoodM.Render(bbDC, m_spriteDC,isVisible[12]);
		mFishFoodN.Render(bbDC, m_spriteDC,isVisible[13]);
		mFishFoodO.Render(bbDC, m_spriteDC,isVisible[14]);
		mFishFoodP.Render(bbDC, m_spriteDC,isVisible[15]);
		mFishFoodQ.Render(bbDC, m_spriteDC,isVisible[16]);
		mFishFoodR.Render(bbDC, m_spriteDC,isVisible[17]);
		mFishFoodS.Render(bbDC, m_spriteDC,isVisible[18]);
		mFishFoodT.Render(bbDC, m_spriteDC,isVisible[19]);
		mFishFoodU.Render(bbDC, m_spriteDC,isVisible[20]);
		mFishFoodV.Render(bbDC, m_spriteDC,isVisible[21]);
		mFishFoodW.Render(bbDC, m_spriteDC,isVisible[22]);
		mFishFoodX.Render(bbDC, m_spriteDC,isVisible[23]);
		mFishFoodY.Render(bbDC, m_spriteDC,isVisible[24]);
		mFishFoodZ.Render(bbDC, m_spriteDC,isVisible[25]);
		mSpace.Render(bbDC, m_spriteDC,isVisible[26]);

		//THE TEXTS TO RENDER
		HFONT hOldFont;	
		COLORREF oldColor;
		HFONT hFont = CreateFont( 15, 15, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Times New Roman" );
		hOldFont = (HFONT)SelectObject( bbDC, hFont );
		SetBkMode( bbDC, TRANSPARENT  );
		oldColor = SetTextColor( bbDC, RGB(0, 0, 0 ) ); 

		//The Score
		char Buffer[50];
		sprintf(Buffer, "SCORE: %i", mScore);
		TextOut( bbDC, 830, 93,  Buffer, strlen(Buffer)); // 
		
		//Time
		char BufferTimer[50];
		sprintf(BufferTimer, "%i Seconds left", (int) mGameTimer);
		TextOut( bbDC, 829, 22,  BufferTimer, strlen(BufferTimer)); //timer

		//HFONT hOldFont2;
		//HFONT hFont2 = CreateFont( 10, 12, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Times New Roman" );
		//hOldFont2 = (HFONT)SelectObject( bbDC, hFont2 );
		
		//THE QUESTION
		oldColor = SetTextColor( bbDC, RGB(0, 0, 255 ) ); 
		if(strlen(mQuestionToShow)>=45)
		{
			TextOut( bbDC, 40, 90,  mQuestionToShow, 45);
		}
		else
		{
			TextOut( bbDC, 40, 90,  mQuestionToShow, strlen(mQuestionToShow));
		}
		if(strlen(mQuestionToShow) > 45)
		{
			char Extra[50];
			for(int x = 0; x<strlen(mQuestionToShow)- 45; x++)
			{
				Extra[x] = mQuestionToShow[x+45];
			}
			TextOut( bbDC, 40, 110,  Extra, strlen(mQuestionToShow)- 45);
		}
		//SelectObject( bbDC, hOldFont );
				
		//NEVER FORGET TO DELETE
		DeleteObject( hFont );	
		DeleteObject( hOldFont);
		
		//THe Score

		//Tiles/Answer
		const int tileWidth = 60; 
		int start = 105;
		for(int  y = 0; y<Ex.GetLength();y++)
		{
			for(int  x= 0; x<27 ;x++)
			{
				if(Ex[y] == Alphabet[x])
					letters[x]->Render(bbDC,m_spriteDC, start+=60, 480); // 50 y
			}
		}		
		
		if(mLives <= 0)
		{
			mStartGame = 0;
			PopUpRender( bbDC, 1);
			ShowCursor();
			
		}
	
		//POpup
		if(ShowPopUpCorrectAnswer )
		{
			PopUpRender(bbDC, 2);
			ShowCursor();
		}
		if(ShowPopUpWrongAnswer)
		{
			PopUpRender(bbDC, 3);
			ShowCursor();

		}
		if(ShowPopUplevel1Complete)
		{
			ShowCursor();
			PopUpRender(bbDC,4);
		}
		if(ShowPopUplevel2Complete)
		{
			ShowCursor();
			PopUpRender(bbDC, 5);
		}
		if(ShowPopUplevel3Complete)
		{
			ShowCursor();
			PopUpRender(bbDC, 6);
		}

			//The Green Fish
		const int GreenFishWidth = 98, GreenFishHeight = 81;

		
		if(popuptimer >=.05f)
		{
			mLastPosX = (float)mousePos.x;
			popuptimer = 0;

		}
		
		static int face = 0;
			if(/*(float)*/mousePos.x > mLastPosX)
			{
				 face = 1;
				m_pMovingGreenFish->Render(bbDC, m_spriteDC, mousePos.x - GreenFishWidth/2 , mousePos.y - GreenFishWidth/2); //so the pointer will point in the center of the image
			}
			else if(mousePos.x < mLastPosX)
			{
				face =2;
				m_pMovingGreenFish2->Render(bbDC, m_spriteDC, mousePos.x - GreenFishWidth/2 , mousePos.y - GreenFishWidth/2); //so the pointer will point in the center of the image
			}
		
			if(/*(float)*/mousePos.x == mLastPosX)
			{
				if(face == 1)
				{
					m_pMovingGreenFish->Render(bbDC, m_spriteDC, mousePos.x - GreenFishWidth/2 , mousePos.y - GreenFishWidth/2); //so the pointer will point in the center of the image
				}
				else if(face == 2)
				{
					m_pMovingGreenFish2->Render(bbDC, m_spriteDC, mousePos.x - GreenFishWidth/2 , mousePos.y - GreenFishWidth/2); //so the pointer will point in the center of the image
				}
			}
			
		m_pBackBuffer->Present();
		return TRUE;
	}

	BOOL LaSalle::OnCreditsUpdate( FLOAT dt )
	{
        POINT mousePos;
		GetAppCursorPos( mousePos );	

		//Credih +=dt;

		RECT RectBackButton;
		RectBackButton.left = 7;
		RectBackButton.top = 15;
		RectBackButton.right = RectBackButton.left + 298;
		RectBackButton.bottom = RectBackButton.top + 46;

		if ( PointRectCollisionCheck( mousePos, RectBackButton ) && IsBufferedKeyDown(VK_LBUTTON))
		{	
			ButtonClick.Play();
			HandleStateChange(MENU);
		}

		return TRUE;
	}

	BOOL LaSalle::OnCreditsRender( void )
	{
		m_pBackBuffer->Clear();
		HDC bbDC = m_pBackBuffer->GetDC();
		//////// BEGIN RENDER ////////////
		m_pCreditsBackground->Render(bbDC, m_spriteDC, 0 ,0 );

		HFONT fontZ;
		COLORREF qTextcolor;
		HFONT hFont = CreateFont(13, 11, 0, 0, FALSE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial");
		fontZ = (HFONT)SelectObject(bbDC, hFont);
		SetBkMode(bbDC, TRANSPARENT);
		qTextcolor = SetTextColor(bbDC, RGB(34, 64, 148)); 
		
				
		char BA[50];
		sprintf(BA,mEngine);

		char PS[50];
		sprintf(PS,mEngine2);

		TextOut(bbDC, 520, 550, BA, strlen(BA));
		TextOut(bbDC, 520, 530, PS, strlen(PS));
	
		POINT mousePos;
		GetAppCursorPos( mousePos );
	
		
		DeleteObject(hFont);
		m_pBackBuffer->Present();

		return TRUE;
	}

	BOOL LaSalle::OnHelpUpdate( FLOAT dt )
	{
		//Credih+=dt;
		POINT mousePos;
		GetAppCursorPos( mousePos );

		RECT RectBackButton;
		RectBackButton.left = 7;
		RectBackButton.top = 15;
		RectBackButton.right = RectBackButton.left + 298;
		RectBackButton.bottom = RectBackButton.top + 46;

		if ( PointRectCollisionCheck( mousePos, RectBackButton ) && IsBufferedKeyDown(VK_LBUTTON))
		{	
			HandleStateChange(MENU);
		}
		return TRUE;
	}
	
	BOOL LaSalle::OnHelpRender( void )
	{
		m_pBackBuffer->Clear();
		HDC bbDC = m_pBackBuffer->GetDC();

		m_pHelpBackground->Render(bbDC, m_spriteDC, 0 ,0 );
	
		m_pBackBuffer->Present();

		return TRUE;
	}

	BOOL LaSalle::OnStoryUpdate( FLOAT dt )
	{
		POINT mousePos;
		GetAppCursorPos( mousePos );

		if(IsBufferedKeyDown(VK_SPACE))
		{
			Review+=1;
		}
		if(Review == 3)
		{
			Review = 0;
		}
		RECT RectBackButton;
		RectBackButton.left = 7;
		RectBackButton.top = 15;
		RectBackButton.right = RectBackButton.left + 298;
		RectBackButton.bottom = RectBackButton.top + 46;

		if ( PointRectCollisionCheck( mousePos, RectBackButton ) && IsBufferedKeyDown(VK_LBUTTON))
		{	
			ButtonClick.Play();
			HandleStateChange(MENU);
		}


		return TRUE;
	}

	BOOL LaSalle::OnStoryRender( void )
	{
        m_pBackBuffer->Clear();

		POINT mousePos;
		GetAppCursorPos( mousePos );

        HDC bbDC = m_pBackBuffer->GetDC();

		if(Review == 0)
		{
			m_pReviewBackground->Render(bbDC, m_spriteDC, 0 ,0 );
		}
		else if(Review == 1)
		{
			m_pReviewBackground2->Render(bbDC, m_spriteDC, 0 ,0 );
		}
		else if(Review == 2)
		{
			m_pReviewBackground3->Render(bbDC, m_spriteDC, 0 ,0 );
		}

		m_pBackBuffer->Present();

		return TRUE;
	}

	BOOL LaSalle::PopUpRender(HDC bbDC, int PopUp)
	{
		POINT mousePos;
		GetAppCursorPos( mousePos );

		ShowCursor();
		RECT RectBackButton;
		RectBackButton.left =393 ;
		RectBackButton.top =308;
		RectBackButton.right = RectBackButton.left + 254;
		RectBackButton.bottom = RectBackButton.top + 24;

		//for the game over
		RECT RectBackButton2;
		RectBackButton2.left =397;
		RectBackButton2.top =284;
		RectBackButton2.right = RectBackButton2.left + 89;
		RectBackButton2.bottom = RectBackButton2.top + 36;

		RECT QuitRect;
		QuitRect.left =526;
		QuitRect.top =283;
		QuitRect.right = QuitRect.left + 94;
		QuitRect.bottom = QuitRect.top + 37;
	
		//m_pBackBuffer->Clear();
       // HDC bbDC = m_pBackBuffer->GetDC();
		if(PopUp == 1&&ShowPopUpWrongAnswer == 0)
		{			
			m_pGameOverPopUp->Render(bbDC,m_spriteDC,302,143);
			if ( PointRectCollisionCheck( mousePos, RectBackButton2 ) && IsBufferedKeyDown(VK_LBUTTON))
			{	
				BckTomain = false;
				HandleStateChange(HighScore);
			}
			else if( PointRectCollisionCheck( mousePos, QuitRect ) && IsBufferedKeyDown(VK_LBUTTON))
			{
				BckTomain = true;
				HandleStateChange(HighScore);
			}
		}
		else if(PopUp == 2 )
		{			
			if( mCorrectAnswers <5 && mCorrectAnswers >0)
			m_pCorrectAnswer->Render(bbDC,m_spriteDC,302,143);
			if ( PointRectCollisionCheck( mousePos, RectBackButton ) && IsBufferedKeyDown(VK_LBUTTON))
			{					
				ShowPopUpCorrectAnswer = 0;
				mStartGame = 1;		
			}			
		}	
		else if(PopUp ==3)
		{
			
			m_pWrongAnswer->Render(bbDC,m_spriteDC,302,143);
			if ( PointRectCollisionCheck( mousePos, RectBackButton ) && IsBufferedKeyDown(VK_LBUTTON))
			{	
				ShowPopUpWrongAnswer = 0;
				mStartGame = 1;		
			}			
		}	
		else if(PopUp == 4)
		{
						
			m_pLevelOneComplete->Render(bbDC,m_spriteDC,302,143);
			if ( PointRectCollisionCheck( mousePos, RectBackButton ) && IsBufferedKeyDown(VK_LBUTTON))
			{	
				ShowPopUplevel1Complete = 0;
				mStartGame = 1;	
			}			
		}
		else if(PopUp == 5)
		{
		
			m_pLevelTwoComplete->Render(bbDC,m_spriteDC,302,143);
			if ( PointRectCollisionCheck( mousePos, RectBackButton ) && IsBufferedKeyDown(VK_LBUTTON))
			{	
				ShowPopUplevel2Complete = 0;
				mStartGame = 1;	
			}			
		}
		else if(PopUp == 6)
		{
			
			m_pLevelThreeComplete->Render(bbDC,m_spriteDC,302,143);
			if ( PointRectCollisionCheck( mousePos, RectBackButton ) && IsBufferedKeyDown(VK_LBUTTON))
			{	
				ShowPopUplevel3Complete = 0;
				HandleStateChange(HighScore);
				mStartGame = 1;
			}			
		}

		//m_pBackBuffer->Present();
		
		return true;
	}

	BOOL LaSalle::OnExitUpdate( FLOAT dt )
	{
		POINT mousePos;
		GetAppCursorPos( mousePos );
		return TRUE;
	}

	BOOL LaSalle::OnExitRender( void )
    {		
        return TRUE;
    }	
	
	BOOL LaSalle::OnLogInUpdate( FLOAT dt)
	{
		POINT Cursor;
		GetAppCursorPos(Cursor);
		
		RECT PlayRect;
		PlayRect.left = 417;
		PlayRect.top = 322;
		PlayRect.right = PlayRect.left + 185;
		PlayRect.bottom = PlayRect.top + 55;

		if ( PointRectCollisionCheck( Cursor, PlayRect ) && IsBufferedKeyDown(VK_LBUTTON))
		{	
			HandleStateChange(Play);
		}

		//ACCEPT INPUT From USER
		//See Ascii Codes for reference http://www.ascii.cl/
		static int Index = 0;
		for (int ascii = 65; ascii <= 90; ascii++)
		{
			int NameLength = strlen(mPlayer.GetName());
			//Cannot accept a blank or More than 7 charactered name
			if( NameLength >= 7)
			{
				//TODO: Insert SOmething
				continue;//jump to next condition in the loop
			}
		
			if(IsBufferedKeyDown(ascii))
			{
				mPlayer.mName[Index] = (char)ascii;
				//Insert your null terminated character
				Index++;
				mPlayer.mName[Index] = '\0';
			}
		}
		if(IsBufferedKeyDown(VK_SPACE))
		{
			mPlayer.mName[Index] = ' ';
			//Insert your null terminated character
			Index++;
			mPlayer.mName[Index] = '\0';
		}
		if(IsBufferedKeyDown(VK_BACK))
		{			
			if(Index > 0 )
			{
				//Allow if index > 0 e.g ., name[1-1] name[0]
				mPlayer.mName[--Index] = '\0'; // not mPlayer.mName[Index--] = '\0';
			}						
		}

		return TRUE;
	}

	BOOL LaSalle::OnLogInRender()
	{
		m_pBackBuffer->Clear();
		HDC bbDC = m_pBackBuffer->GetDC();

		m_pLogInBackGround->Render(bbDC, m_spriteDC, 0, 0);

		HFONT hOldFont;
		COLORREF oldColor;
		HFONT hFont = CreateFont( 44, 30, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Times New Roman" );
		hOldFont = (HFONT)SelectObject( bbDC, hFont );
		SetBkMode( bbDC, TRANSPARENT  );

		oldColor = SetTextColor( bbDC, RGB(0, 0, 0 ) ); 
			
		
		//Check if mPlayer.name is null
		//assert(mPlayer.GetName());

		if(mPlayer.GetName())
			TextOut( bbDC, 366 , 230, mPlayer.GetName(), strlen(mPlayer.GetName() )); //time
		
		SelectObject( bbDC, hOldFont );
		//NEVER FORGET TO DELETE.. It paints every frame so you've got to delete 
		DeleteObject( hFont );	
		DeleteObject( hOldFont);


		m_pBackBuffer->Present();
		return TRUE;		
	}	

	
	BOOL LaSalle::OnHighScoreUpdate( FLOAT dt )
	{
		POINT mousePos;
		GetAppCursorPos( mousePos );		
		
		const int arraysize = 12;

		if(getInputFile)
		{				
			ifstream getnamefile2( "xxxxx5.txt" );
			if( getnamefile2.is_open() )
			{
				for(int x = 0; x<12;x++)
				{
					getnamefile2>>HSCORE[x];
					
					if(HSCORE[x] < 0)
					{
						HSCORE[x] = 0;
					}
				}
				getnamefile2.close();
				HSCORE[11] = mScore;
			}
			getInputFile = false;
			getOutPutFile = true;
			
			//for the user							
		}
	
		if(mScore > HSCORE[0])//highest ever
		{
			//write
			ofstream outFileUser ("High.txt", fstream::in | fstream::out |fstream::binary);

			if(outFileUser)
			{		
				outFileUser<<"\n"<<mPlayer.GetName();
				outFileUser.close();				
			}	
			//read
			ifstream getnamefileuser ("High.txt" );
			if( getnamefileuser.is_open() )
			{
				getnamefileuser>>TopOne;

				getnamefileuser.close();			
			}
		}
		else if(mScore <= HSCORE[0])
		{
			ifstream getnamefileuser ("High.txt" );
			if( getnamefileuser.is_open() )
			{
				getnamefileuser>>TopOne;

				getnamefileuser.close();			
			}
		}


		//bubble sort
		for(int y=0; y < arraysize; y++)
		{
			for ( int k =0; k < arraysize -1-y; k++ )
				if(HSCORE[k]<HSCORE[k+1])
				{
					int temp = HSCORE[k+1];
					HSCORE[k+1] = HSCORE[k];
					HSCORE[k] = temp;
				}
		}		

		if(getOutPutFile )
		{				
			ofstream outFile ("xxxxx5.txt", fstream::in | fstream::out);

			if(outFile)
			{
				for(int x = 0; x<12;x++)
				{
					outFile<<"\n"<<HSCORE[x];
				}
				outFile.close();

			}			
			getOutPutFile = false;			
		}

	
		

		RECT RectBackButton;
		RectBackButton.left =480;
		RectBackButton.top = 440;
		RectBackButton.right = RectBackButton.left + 143;
		RectBackButton.bottom = RectBackButton.top + 74;

		if ( PointRectCollisionCheck( mousePos, RectBackButton ) && IsBufferedKeyDown(VK_LBUTTON))
		{	
			ButtonClick.Play();
			if(BckTomain)
			{
				HandleStateChange(MENU);
			}
			else
			{
				HandleStateChange(Play);
			}
		}
	
		return TRUE;
	}

	BOOL LaSalle::OnHighScoreRender( void )
    {		
		m_pBackBuffer->Clear();
		HDC bbDC = m_pBackBuffer->GetDC();

		HFONT fontZ;
		COLORREF qTextcolor;
		HFONT hFont = CreateFont(18, 15, 0, 0, FALSE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial");
		fontZ = (HFONT)SelectObject(bbDC, hFont);
		SetBkMode(bbDC, TRANSPARENT);
		qTextcolor = SetTextColor(bbDC, RGB(34, 64, 148)); 
		
		m_pHighScoreBg->Render(bbDC, m_spriteDC, 0, 0);
		//Score->Render(bbDC, m_spriteDC, 0, 0);
		
		char SL2[20];
		sprintf(SL2, "%d",HSCORE[0]);
		char SL3[20];
		sprintf(SL3, "%d",HSCORE[1]);
		char SL4[20];
		sprintf(SL4, "%d",HSCORE[2]);
		char SL5[20];
		sprintf(SL5, "%d",HSCORE[3]);
		char SL6[20];
		sprintf(SL6, "%d",HSCORE[4]);
		char SL7[20];
		sprintf(SL7, "%d",HSCORE[5]);
		char SL8[20];
		sprintf(SL8, "%d",HSCORE[6]);
		char SL9[20];
		sprintf(SL9, "%d",HSCORE[7]);
		char SL10[20];
		sprintf(SL10,"%d",HSCORE[8]);
		char SL11[20];
		sprintf(SL11,"%d",HSCORE[9]);
		
		char Top[50];
		sprintf(Top,"%s  %d points",TopOne ,HSCORE[0]);


		TextOut(bbDC, 411, 52 + 160, SL2, strlen(SL2));
		TextOut(bbDC, 411, 72 + 160, SL3, strlen(SL3));
		TextOut(bbDC, 411, 96+ 160, SL4, strlen(SL4));
		TextOut(bbDC, 411, 116+ 160, SL5, strlen(SL5));
		TextOut(bbDC, 411, 136+ 160, SL6, strlen(SL6));
		TextOut(bbDC, 411, 158+ 160, SL7, strlen(SL7));
		TextOut(bbDC, 411, 180+ 160, SL8, strlen(SL8));
		TextOut(bbDC, 411, 200+ 160, SL9, strlen(SL9));
		TextOut(bbDC, 411, 220+ 160, SL10, strlen(SL10));
		TextOut(bbDC, 411, 242+ 160, SL10, strlen(SL11));

		TextOut(bbDC, 411, 133, Top, strlen(Top));

		DeleteObject(hFont);
		
		m_pBackBuffer->Present();
		
		return TRUE;

    }	

	void LaSalle::SaveLoad()
	{
		//ofstream outFile("Fifi.txt");
	
	}

	void LaSalle::IsGameOver(void)
	{
		HandleStateChange(Play);		
	}
	

	// This is a rough implementation of Rect on Rect SAT (Seperation Axis Theory)
	Pulse::BOOL RectToRectCollision( RECT &r1, RECT &r2, Vector2 &pushVec )
	{
		Vector2 rec1[4] = { Vector2((FLOAT)r1.left, (FLOAT)r1.top ), Vector2( (FLOAT)r1.right, (FLOAT)r1.top ),
		Vector2( (FLOAT)r1.right, (FLOAT)r1.bottom ), Vector2( (FLOAT)r1.left, (FLOAT)r1.bottom ) };
		Vector2 rec2[4] = { Vector2((FLOAT)r2.left, (FLOAT)r2.top ), Vector2( (FLOAT)r2.right, (FLOAT)r2.top ),
		Vector2( (FLOAT)r2.right, (FLOAT)r2.bottom ), Vector2( (FLOAT)r2.left, (FLOAT)r2.bottom ) };
		Vector2 axis;
		Vector2 perp;
		Vector2 toVert;
		FLOAT distance;
		UINT positives, negatives;
		Pulse::BOOL isIn;
		FLOAT len;
		FLOAT leastNeg = -FLT_MAX;

		for( UINT i = 0; i < 4; ++i )
		{
			// Seperation axis
			axis.x = rec1[(i + 1) % 4].x - rec1[i].x;
			// Remember that y goes from above to below. So we need to reverse the sign...
			axis.y = -(rec1[(i + 1) % 4].y - rec1[i].y);

			// Make seperation axis a normal vector
			len = sqrtf( axis.x * axis.x + axis.y * axis.y );
			axis.x /= len;
			axis.y /= len;

			// Get the perpendicular vector (perpendicular to the seperation axis)
			perp.x = -axis.y;
			perp.y = axis.x;

			positives = negatives = 0;
			isIn = FALSE;

			// Check each vertex in rec2 if its in or out
			for( UINT j = 0; j < 4; ++j )
			{
				// Vertex from the first rect to the vertex we're currently testing
				toVert.x = rec2[j].x - rec1[i].x; 
				toVert.y = -(rec2[j].y - rec1[i].y);  // Reverse sign

				// Get distance/lenght
				distance = perp.x * toVert.x + perp.y * toVert.y;

				distance > 0 ? ++positives : ++negatives;

				//if ( positives && negatives )
				//	return TRUE; // Oh its definitely in.

				if ( distance < 0 )
				{
					// Look for the least negative
					if  ( distance > leastNeg )
					{
						// Replace leastNeg
						leastNeg = distance;
						pushVec.x = perp.x * distance;
						pushVec.y = -perp.y * distance;
					}
					isIn = TRUE;
				}
			}

			// If all vertices passed as in front of one seperation axis,
			// then rect is not in.
			if ( isIn == FALSE )
			{
				pushVec.x = pushVec.y = 0;
				return FALSE;
			}
		}

		// All checks specifies that all the vertices are in so we have a collision
		return TRUE;
	}

	// Rect - Sphere SAT
	Pulse::BOOL RectToSphereCollision( RECT &r, FPoint &ball, FLOAT radius, Vector2 &pushVec )
	{
		Vector2 rec[4] = { Vector2( (FLOAT)r.left, (FLOAT)r.top ), Vector2( (FLOAT)r.right, (FLOAT)r.top ), 
			Vector2( (FLOAT)r.right, (FLOAT)r.bottom ), Vector2( (FLOAT)r.left, (FLOAT)r.bottom ) };
		Vector2 axis;
		Vector2 perp;
		Vector2 toVert;
		FLOAT distance;
		Vector2 closestVert;
		Pulse::BOOL isIn;
		FLOAT len;
		FLOAT leastNeg = -FLT_MAX; // Make this the negative minimum

		for( UINT i = 0; i < 4; ++i )
		{
			// Seperation axis
			axis.x = rec[(i + 1) % 4].x - rec[i].x;
			// Remember that y goes from above to below. So we need to reverse the sign...
			axis.y = -(rec[(i + 1) % 4].y - rec[i].y);

			// Make seperation axis a normal vector
			len = sqrtf( axis.x * axis.x + axis.y * axis.y );
			axis.x /= len;
			axis.y /= len;

			// Get the perpendicular vector (perpendicular to the seperation axis)
			perp.x = -axis.y;
			perp.y = axis.x;

			isIn = FALSE;

			// Find the nearest vertex of the sphere based on the reversed normal vector
			toVert.x = -perp.x;
			toVert.y = perp.y; // remember perp.y is already reveresed.
			closestVert.x = ball.x + toVert.x * radius;
			closestVert.y = ball.y + toVert.y * radius;

			// Vertex from the first rect to the vertex we're currently testing
			toVert.x = closestVert.x - rec[i].x; 
			toVert.y = -(closestVert.y - rec[i].y);  // Reverse sign

			// Get distance/lenght
			distance = perp.x * toVert.x + perp.y * toVert.y;

			if ( distance < 0 )
			{
				// Look for the least negative
				if  ( distance > leastNeg )
				{
					// Replace leastNeg
					leastNeg = distance;
					pushVec.x = perp.x * distance;
					pushVec.y = -perp.y * distance;
				}
				isIn = TRUE;
			}

			// If all vertices passed as in front of one seperation axis,
			// then rect is not in.
			if ( isIn == FALSE )
			{
				pushVec.x = pushVec.y = 0;
				return FALSE;
			}
		}

		return TRUE;
	}


}